﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors; 
using System.Data.SqlClient;
using System.Collections;
using UFIDA.U8C.AnLianDB;

namespace AnLianSysClient
{
    public partial class frmSupplier : DevExpress.XtraEditors.XtraForm
    {
        const string regKey = "DevExpress\\XtraGrid\\Layouts\\frmSupplier";

        public frmSupplier()
        {
            InitializeComponent();  
        } 

        private void GdvSupplier_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
        }

        private void FrmSupplier_Load(object sender, EventArgs e)
        {
            gdsupplier.MainView.RestoreLayoutFromRegistry(regKey);//读取（还原）布局 
        }

        private void FrmSupplier_FormClosed(object sender, FormClosedEventArgs e)
        {
            gdsupplier.MainView.SaveLayoutToRegistry(regKey); //保存布局
        }

        private void BtnQuery_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Query();
        }

        private void Query()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select *, case iflag when 1 then '是' else '否' end cflag from  wazh_supplier ");

            if (!string.IsNullOrEmpty(edtCode.Text))
            {
                sql.Append(" and supplier like '%" + edtCode.Text + "%'");
            }

            if (!string.IsNullOrEmpty(edtName.Text))
            {
                sql.Append(" and suppliername like '%" + edtName.Text + "%'");
            }

            if (!string.IsNullOrEmpty(edtClass.Text))
            {
                sql.Append(" and supplierclass like '%" + edtClass.Text + "%'");
            }

            if (!string.IsNullOrEmpty(cbsync.Text))
            {
                if (cbsync.Text.Equals("是"))
                {
                    sql.Append(" and iflag = 1");
                }
                else
                {
                    sql.Append(" and iflag = 0");
                }
            }
            gdsupplier.DataSource = null;
            dssupplier = UFIDA.MYSQL.DB.DbHelperSQL.Query(sql.ToString(), "supplier", UFIDA.U8C.AnLianDB.common.mysqlconn());
            gdsupplier.DataSource = bdsSupplier;
            bdsSupplier.DataSource = dssupplier;
            bdsSupplier.DataMember = "supplier";
            
        }
    }
}